package ar.edu.utn.frsf.proyectofinal.sistemadecontrolmodbus.service.factories.imp;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import ar.edu.utn.frsf.proyectofinal.sistemadecontrolmodbus.persistence.model.Alarm;
import ar.edu.utn.frsf.proyectofinal.sistemadecontrolmodbus.persistence.model.Device;
import ar.edu.utn.frsf.proyectofinal.sistemadecontrolmodbus.service.AlarmService;
import ar.edu.utn.frsf.proyectofinal.sistemadecontrolmodbus.service.FieldService;
import ar.edu.utn.frsf.proyectofinal.sistemadecontrolmodbus.service.factories.AlarmServiceFactory;
import ar.edu.utn.frsf.proyectofinal.sistemadecontrolmodbus.service.factories.FieldServiceFactory;
import ar.edu.utn.frsf.proyectofinal.sistemadecontrolmodbus.service.imp.AlarmServiceImp;
import ar.edu.utn.frsf.proyectofinal.sistemadecontrolmodbus.persistence.DeviceDAO;

@Component
public class AlarmServiceFactoryImp implements AlarmServiceFactory {

	@Autowired(required = true)
	private DeviceDAO devicedao;
	@Autowired(required = true)
	private FieldServiceFactory fieldservicefactory;
	
	@Override
	public List<AlarmService> create(List<Alarm> devalarms, Device device, Map<Integer,FieldService> fieldServices) {
		List<AlarmService> ret = new ArrayList<AlarmService>();
		for (Alarm alarm : devalarms) {
			ret.add(create(alarm,device,fieldServices.get(alarm.getField().getID())));
		}
		return ret;
	}

	@Override
	public AlarmService create(Alarm alarm, Device device, FieldService fieldServ){
		AlarmServiceImp nserv = new AlarmServiceImp();
		nserv.setAlarm(alarm);
		nserv.setField(fieldServ);
		return nserv;
	}
	/**
	 * @return the devicedao
	 */
	public DeviceDAO getDevicedao() {
		return devicedao;
	}
	/**
	 * @param devicedao the devicedao to set
	 */
	public void setDevicedao(DeviceDAO devicedao) {
		this.devicedao = devicedao;
	}

	/**
	 * @return the fieldservicefactory
	 */
	public FieldServiceFactory getFieldservicefactory() {
		return fieldservicefactory;
	}

	/**
	 * @param fieldservicefactory the fieldservicefactory to set
	 */
	public void setFieldservicefactory(FieldServiceFactory fieldservicefactory) {
		this.fieldservicefactory = fieldservicefactory;
	}
}
